class ILFuncs
  attr_accessor :panel
  def initialize(pane)
    @ins=pane
    @panel=Wx::Panel::new pane
    @panel.set_sizer Wx::BoxSizer::new(Wx::VERTICAL)
    @panel.sizer.add 20,20
    siz=Wx::StaticBoxSizer::new(Wx::VERTICAL,@panel,"Server Module Objects")
    @panel.sizer.add(siz,0,Wx::EXPAND)
    siz1=Wx::BoxSizer::new(Wx::HORIZONTAL)
    siz1.add Wx::StaticText::new(@panel,-1,"#DBREF:")
    siz1.add 20,20
    dbref = Wx::TextCtrl::new(@panel,-1)
    siz1.add dbref
    siz1.add 40,40
    siz1.add Wx::Button::new(@panel,3333,"Realize Object From Server")
    @panel.evt_button(3333) {|evt| 
        object = $client.client.type.realiseObject(object,dbref.value,$client.client)
        add_object object,$client.instance_variable_get("@ins").get_object_list
    }
    siz.add siz1

    siz1=Wx::BoxSizer::new(Wx::HORIZONTAL)
    siz1.add Wx::StaticText::new(@panel,-1,"#DBREF:")
    siz1.add 20,20
    dbref1 = Wx::TextCtrl::new(@panel,-1)
    siz1.add dbref1
    siz1.add 40,40
    siz1.add Wx::Button::new(@panel,3334,"Create YAML DB from Server Object")
    @panel.evt_button(3334) {|evt|
     
      obj=$objects.find {|o| o.dbref==dbref1.value}
      pobj=PObj::new(nil,obj.dbref,"objID-#{obj.dbref}")
      obj.attributes[:at].each_key {|k|
        pobj.attributes[:at][k.to_s]=obj.attributes[:at][k.to_s.to_sym][:data].value
      }
      obj.attributes[:and].each_key {|k|
        pobj.attributes[:and][k.to_s]=obj.attributes[:at][k.to_s.to_sym][:data].value
      }
      pobj.write
      create_intermediateObject_yamlFile obj
     
    }
    siz.add siz1
    siz3=Wx::StaticBoxSizer::new(Wx::HORIZONTAL,@panel,"Add YAML Db File to project")
    siz3.add Wx::StaticText::new(@panel,-1,"Project name:")
    siz3.add 20,20
    name = Wx::TextCtrl::new(@panel,-1)
    siz3.add name
    siz3.add 20,20
    siz3.add Wx::StaticText::new(@panel,-1,"YAML Db File:")
    siz3.add 20,20
    dbref2=Wx::TextCtrl::new(@panel)
    siz3.add dbref2
    siz3.add 20,20
    siz3.add Wx::Button::new(@panel,4445,"Choose")
    @panel.evt_button(4445) {|evt|
     dlg = Wx::FileDialog.new(@panel, "Chhose a object config file",
     "", "", "Object Config Files(*.ocfg)|*.ocfg",
     Wx::OPEN, Wx::DEFAULT_POSITION)    #
     dlg.set_directory("#{Dir.getwd}/data")
     dlg.show_modal
     file = dlg.get_path
     dbref2.value = file
    }
    siz3.add 20,20
    siz3.add Wx::Button::new(@panel,4444,"Add")
    @panel::evt_button(4444) {|evt|
      n=name.value
      f=dbref2.value
      get_project(n).objects << f
      @ins.add_pobj get_project(n).pname,YAML::load_file(f).dbref+" -- "+YAML::load_file(f).oname,YAML::load_file(f)
      get_project(n).write
    }
    siz.add 20,20
#     siz.add siz3,0,Wx::EXPAND 
    @panel.sizer.add 30,30
    @panel.sizer.add siz3,0,Wx::EXPAND
    @panel.sizer.add 30,30
    siz=Wx::StaticBoxSizer::new(Wx::VERTICAL,@panel,"YAML DataBase Objects")
    @panel.sizer.add(siz,0,Wx::EXPAND)
    siz1=Wx::BoxSizer::new(Wx::HORIZONTAL)
    siz1.add Wx::StaticText::new(@panel,-1,"File:")
    siz1.add 20,20
    f = Wx::TextCtrl::new(@panel,-1,:size=>Wx::Size::new(110,-1))
    siz1.add f
    siz1.add 40,40
    siz1.add Wx::Button::new(@panel,3335,"Choose")
     @panel.evt_button(3335) {|evt|
       dlg = Wx::FileDialog.new(@panel, "Choose a object config file",
       "", "", "Object Config Files(*.ocfg)|*.ocfg",
       Wx::OPEN, Wx::DEFAULT_POSITION)    #
       dlg.set_directory("#{Dir.getwd}/data")
       dlg.show_modal
       file = dlg.get_path
       f.value = file
     }
    siz1.add 20,20
    siz1.add Wx::StaticText::new(@panel,-1,"Attribute:")
    siz1.add 20,20
    attr=Wx::TextCtrl::new(@panel)
    siz1.add attr
    siz1.add 20,20
    siz1.add Wx::Button::new(@panel,3336,"Sync Object to Server")
    @panel.evt_button(3336) {|evt|
      atty=attr.value
      m=pane.instance_variable_get("@server").module
      m=$client.client.type
      socket=$client.client.socket
      obj = YAML.load_file(f.value)
      if obj.functions.find {|a| a[0]==atty}
        type = "@functions"
      elsif obj.commands.find {|a| a[0]==atty}
        type = "@commands"
      elsif obj.attributes.find {|a| a[0]==atty}
        type = "@attributes"
      end
      if atty = ""
        wobj = YAML.load_file(f.value)
        wobj.attributes[:and].each_key {|att|
          $client.client.type.sync_from_yaml wobj,type,att.to_s,socket
        }
      else
        $client.client.type.sync_from_yaml YAML.load_file(f.value),type,attr.value,socket
      end
    }
    siz.add siz1

    siz1=Wx::BoxSizer::new(Wx::HORIZONTAL)
    siz1.add Wx::StaticText::new(@panel,-1,"File:")
    siz1.add 20,20
    f1 = Wx::TextCtrl::new(@panel,-1,:size=>Wx::Size::new(110,-1))
    siz1.add f1
    siz1.add 40,40
    siz1.add Wx::Button::new(@panel,3337,"Choose")
      @panel.evt_button(3337) {|evt|
       dlg = Wx::FileDialog.new(@panel, "Choose a object config file",
       "", "", "Object Config Files(*.ocfg)|*.ocfg",
       Wx::OPEN, Wx::DEFAULT_POSITION)    #
       dlg.set_directory("#{Dir.getwd}/data")
       dlg.show_modal
       file = dlg.get_path
       f1.value = file
     }
    siz1.add 20,20
    b = Wx::Button::new(@panel,3338,"Create Server Object from YAML DB")
    siz1.add b
    b.disable
    siz.add siz1
  end
end